// ChatServerProxyDoc.cpp : implementation file
//

#include "stdafx.h"
#include "Chat.h"
#include "ChatServerProxyDoc.h"


// CChatServerProxyDoc

IMPLEMENT_DYNCREATE(CChatServerProxyDoc, CChatBaseDoc)

CChatServerProxyDoc::CChatServerProxyDoc()
: m_pUdpProxyServer(NULL)
{
}

BOOL CChatServerProxyDoc::OnNewDocument()
{
	if (!CChatBaseDoc::OnNewDocument())
		return FALSE;

	m_pUdpProxyServer = new RakNet::UDPProxyServer; 
	AttachRaknetPlugin(m_pUdpProxyServer);

	StartUpRaknet(MAX_CHAT_CLIENTS, 30, &SocketDescriptor(), 1);
	return TRUE;
}

CChatServerProxyDoc::~CChatServerProxyDoc()
{
	if (m_pUdpProxyServer)
	{
		DetachRaknetPlugin(m_pUdpProxyServer);
		delete m_pUdpProxyServer;
		m_pUdpProxyServer = NULL;
	}
}


BEGIN_MESSAGE_MAP(CChatServerProxyDoc, CChatBaseDoc)
END_MESSAGE_MAP()


// CChatServerProxyDoc diagnostics

#ifdef _DEBUG
void CChatServerProxyDoc::AssertValid() const
{
	CChatBaseDoc::AssertValid();
}

#ifndef _WIN32_WCE
void CChatServerProxyDoc::Dump(CDumpContext& dc) const
{
	CChatBaseDoc::Dump(dc);
}
#endif
#endif //_DEBUG

#ifndef _WIN32_WCE
// CChatServerProxyDoc serialization

void CChatServerProxyDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}
#endif


// CChatServerProxyDoc commands

bool CChatServerProxyDoc::LoginToCoordinator( const RakNet::RakString& password, const SystemAddress& coordinatorAddress )
{
	return m_pUdpProxyServer->LoginToCoordinator(password, coordinatorAddress);
}